package com.yztc.ui.details.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yztc.bean.details.ListBean;
import com.yztc.chunboapp.R;
import com.yztc.utils.ImageHelper;

import java.util.List;

/**
 * Created by My on 2016/10/16.
 */
public class DetailsBaseAdapter extends BaseAdapter{
    private List<ListBean> list;
    private Context mContext;
    private int num;
    public DetailsBaseAdapter(Context mContext,List<ListBean> list){
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public int getCount() {
                return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    ViewHolder holder = null;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_details_listview_item,null);
            holder = new ViewHolder();
            holder.mLineDetailsUrl = (LinearLayout) convertView.findViewById(R.id.line_details_url);
            holder.mTVPhoneNumber = (TextView) convertView.findViewById(R.id.tv_phoneNumber);
            holder.mTVDate = (TextView) convertView.findViewById(R.id.tv_date);
            holder.mTVContent = (TextView) convertView.findViewById(R.id.tv_content);
            holder.mTVCreateDate = (TextView) convertView.findViewById(R.id.tv_createDate);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
            holder.mTVPhoneNumber.setText(list.get(position).getNickname());
            holder.mTVDate.setText(list.get(position).getUserCreationTime()+"加入");
            holder.mTVContent.setText(list.get(position).getComment());
            holder.mTVCreateDate.setText(list.get(position).getCreationTime());
            if (list.get(position).getUrl() != null && list.get(position).getUrl().size() != 0){
                for (int i=0;i<list.get(position).getUrl().size();i++){
                    String imageBaseUrl = "http://i3.chunboimg.com/";
                    ImageView iv = new ImageView(mContext);
                    ImageHelper.getNormalImage(mContext,imageBaseUrl+list.get(position).getUrl().get(i),iv);
                    iv.setMaxWidth(150);
                    iv.setMaxHeight(150);
                    iv.setAdjustViewBounds(true);
                    holder.mLineDetailsUrl.addView(iv);
                }

            }
        return convertView;
    }

    static class ViewHolder{
        TextView mTVPhoneNumber,mTVDate,mTVContent,mTVCreateDate;
        LinearLayout mLineDetailsUrl;
    }
}
